package se.webbzon.oschi01.nbt;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

import se.webbzon.oschi01.utils.Reader;

import com.googlecode.asmack.connection.impl.ZLibInputStream;

public class NBTInputStreamReader extends AbstractNBTReader implements Reader<Tag<?>,InputStream> {
	
	private NBTCompression compression;
	
	public NBTInputStreamReader() {
		this(NBTCompression.NONE);
	}
	
	public NBTInputStreamReader(NBTCompression compression) {
		this.compression = compression;
	}
	
	@Override public Tag<?> read(InputStream source) throws IOException {
		switch (compression) {
		case ZLIB:
			return super.read(new DataInputStream(new ZLibInputStream(source)));
		case GZIP:
			return super.read(new DataInputStream(new GZIPInputStream(source)));
		default:
			return super.read(new DataInputStream(source));
		}
	}
	
}
